package ar.edu.utn.frsf.cidisi.upcolbpip.upgen;

import java.io.IOException;
import java.util.HashMap;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import ar.edu.utn.frsf.cidisi.upcolbpip.UPColBPIPModel;

public class WriteUPColBPIPFile {

	WriteUPColBPIPFile() {}
	
	public Resource createUPColBPIPFile(String path,UPColBPIPModel modelUpcolbpip) {

		// create the resource and add the net to it
//		ResourceSet resourceSet = new ResourceSetImpl();
				

		// create the resource and add the net to it
		ResourceSet resourceSet = new ResourceSetImpl();

		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
		.put( "upcolbpip",new XMIResourceFactoryImpl());
				
		final URI uri = URI.createFileURI("modelUpcolbpip.upcolbpip");
		
		final Resource newResource = resourceSet.createResource(uri);
	
/*		
		ResourceSet resourceSet = new ResourceSetImpl();
		
		final URI uri = URI.createURI("platform:"+"modelo.upcolbpip");
		
		final Resource newResource = resourceSet.createResource(uri);
	*/	
	//	final URI uri = URI.createURI("platform:"+path);
	//	final URI uri = URI.createURI("platform:resource/ar.edu.utn.frsf.cidisi.upcolbpip.generator/modelUpcolbpip.upcolbpip");
		
		
		EList<EObject> contents = newResource.getContents();
		
		contents.add(modelUpcolbpip); 
		
		try {
			
			newResource.save(new HashMap<Object, Object>());
			
		} catch (IOException e) {
			return null;
		}
		
		return newResource;
		
	}
	
}
